package foo.bar.wiki.web.action.general;

import foo.bar.wiki.web.action.BaseActionBean;
import foo.bar.wiki.web.nonextension.NullResolution;
import foo.bar.wiki.services.UserService;
import net.sourceforge.stripes.action.*;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.integration.spring.SpringBean;
import org.apache.shiro.SecurityUtils;

/**
 * @author tmjee
 * @version $Date$ $Id$
 */
public class LoginActionBean extends BaseActionBean {

    public static final String VIEW = "/general/login.jsp";

    private UserService userService;

    @Validate(trim = true, required = true, on={"login"})
    private String username;

    @Validate(trim=true, required = true, on={"login"})
    private String password;

    @DefaultHandler
    public Resolution view() {
        return new ForwardResolution(generateThemePath(VIEW));
    }


    public Resolution login() {
        // if login is successfull, jSecurity will have done a redirect to
        // authc.successUrl in web.xml, so we will only reach here when
        // threre's a login error.
        return new ForwardResolution(generateThemePath(VIEW));
    }


    @SpringBean("userService")
    public void setUserService(UserService userService) {
        this.userService = userService;
    }


    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}


